<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@page import="comm.util.SoptHashMap"%>
<%@page import="comm.util.RequestManager"%>
<%@page import="java.util.ArrayList"%>
<%@page import="org.json.JSONObject"%>
<%@page import="org.json.JSONArray"%><jsp:useBean id="contentsProc" class="com.sopt.contents.ContentsProc"/>
<jsp:useBean id="memProc" class="com.sopt.member.MemberProc"/>

<%
	int curSeq = 0;

	SoptHashMap hm = RequestManager.getRequest(request);
	if(hm.get("NUMBER")!=null && hm.get("NUMBER").toString().length()>0 && memProc.isExistMember(hm.get("NUMBER").toString())){
		String curNum = hm.get("NUMBER").toString();
		curSeq = memProc.getMemberSeqByNumber(curNum);
		ArrayList<SoptHashMap> contentList = contentsProc.getMessageListByMemberSeq(curSeq);
		
		ArrayList<Integer> readContentSeqs = new ArrayList<Integer>();
		
		for(SoptHashMap curMap : contentList)readContentSeqs.add(Integer.parseInt(curMap.get("CONTENTS_SEQ").toString()));
		
		boolean checkedRead = contentsProc.updateToReadContents(readContentSeqs);
		if(!checkedRead){
			System.out.println("읽음 표시 에러-ㅁ-");
		}
		
		JSONObject resultJson = new JSONObject(); 
		resultJson.put("result",new JSONArray(contentList));
		
		out.println(resultJson.toString());
		
	}else{
		out.println("ERROR");
	}
%>